package org.example.volunteerend.controller;

import java.util.Map;

import org.example.volunteerend.common.Result;
import org.example.volunteerend.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/home")
public class HomeController {

    private final HomeService homeService;

    @Autowired
    public HomeController(HomeService homeService) {
        this.homeService = homeService;
    }

    /**
     * 获取首页数据
     */
    @GetMapping
    public Result<Map<String, Object>> getHomeData() {
        try {
            Map<String, Object> data = homeService.getHomeData();
            return Result.success("success", data);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("获取首页数据失败：" + e.getMessage());
        }
    }
} 